﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Cashier
{
    /// <summary>
    /// SellOffWindow.xaml 的交互逻辑
    /// </summary>
    public partial class SellOffWindow : Window
    {
        public SellOffWindow(List<string> namelist)
        {
            InitializeComponent();
            this.nameList = namelist;
        }

        public List<string> nameList;

        private void btnAddSellOffItem_Click(object sender, RoutedEventArgs e)
        {
            AddSellOffItemWindow addWin = new AddSellOffItemWindow();
            addWin.Owner = this;
            addWin.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            if (addWin.ShowDialog() == true)
            {
                AccessText tmpAT = new AccessText();
                tmpAT.Text = addWin.selectedDishName;
                tmpAT.TextWrapping = TextWrapping.Wrap;
                tmpAT.HorizontalAlignment = HorizontalAlignment.Left;
                tmpAT.VerticalAlignment = VerticalAlignment.Center;

                Button tmpBtn = new Button();
                tmpBtn.Margin = new Thickness(5, 5, 5, 5);
                tmpBtn.FontSize = 18;
                tmpBtn.Content = tmpAT;
                tmpBtn.Click += new RoutedEventHandler(tmpBtn_Click);

                btnPanel.Children.Add(tmpBtn);
                nameList.Add(addWin.selectedDishName);
            }
        }

        void tmpBtn_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("删除此沽清项？", "确认", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                btnPanel.Children.Remove(sender as Button);
                nameList.Remove(((sender as Button).Content as AccessText).Text);
            }
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
